# -*- coding:utf8 -*-
#encoding = utf-8
__author__ = 'man'

#		_________________________________________________________________________________
#
#						漫鸽网络技术服务(mangenotwork)拥有所有权
#						@www.hbsj.xyz   
#						@www.mangenotwork.com
#			严重声明：原始代码属于"漫鸽网络技术服务(mangenotwork)"的知识产权，拥有法律的保护，
#		请勿抄袭、转载、删除、私用、篡改、破坏...
#
#       
#		简介 ：  query.py 查询API，查询的接口与方法
#		作者 ： 李漫(man)
#		创建时间:  20190620
#		
#		_________________________________________________________________________________

from flask import Flask,request,g,render_template,redirect,url_for,abort,session,jsonify,current_app
from flask import Blueprint , render_template
from flask import make_response,Response 
import sys,os
import json
import time
import datetime
import random
import redis
from cryptography.fernet import Fernet
import hashlib
#db 交互库
import db.mandb



query = Blueprint('query',__name__)

#函数不能命名 test
@query.route('/query_test', methods=['POST','GET'])
def query_test():
	return "This is a Blueprint : query Test."


#数据库连接
def ManDB(func=None, param=None):
	def deco(func):
		def wrapper(*args,**kwargs):
			man_db = db.mandb.DB()
			return func(man_db,*args,**kwargs)			
		wrapper.__name__ = func.__name__
		return wrapper
	return deco if not func else deco(func)


'''
					#类型： 函数,方法
					#用户认证
'''
def userACC():
    userToken=request.cookies.get('user_token')
    print("[Get Cookies] = "+str(userToken))
    username=request.cookies.get('user_name')
    print("[Get username] = "+str(username))

    keys = session.get(userToken)
    print("[Get keys] = "+str(keys))
    if userToken != None and keys == username:
        return keys
    else:
        return False


'''
					#类型： DB交互
					#搜索商品信息
'''
@ManDB
def all_query_1(man_db,inputdata,pgnumber=0):
	pgnumber+=1
	sql_sqlect_all_1 ="\
		SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from jd_pachong_data_1\
				WHERE "+inputdata+"\
				\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tb_tm_pachong_data_1\
				WHERE "+inputdata+"\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from sn_pachong_data_1\
				WHERE "+inputdata+"\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		) as t\
		ORDER BY cod_sales+0 DESC \
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	#print(return_datas)
	"""
	count_query(
	count_key char(30)  NOT NULL,/* 查询内容 */
	count_time char(30) NOT NULL,/* 查询时间 */
	"""
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time) VALUES ( '"+inputdata+"', '"+str(ticks)+"');"
	man_db.execute(add_count)
	return return_datas


'''
						#类型： DB交互
						#首页加载商品信息1
'''
@ManDB
def home_query_1(man_db,inputdata,pgnumber=0,username = ""):
	#pgnumber+=1
	print(username)
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*10)+",10\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		) as t\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	#print(return_datas)
	ticks = time.time()
	print("[*** username ***]"+username)
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


'''
						#类型： DB交互
						#首页加载商品信息2
'''
@ManDB
def home_query_2(man_db,inputdata,pgnumber=0):
	pgnumber+=1
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1\
				WHERE cod_fenlei = '"+inputdata+"'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1\
				WHERE cod_fenlei = '"+inputdata+"'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*10)+",10\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				WHERE cod_fenlei = '"+inputdata+"'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(pgnumber*5)+",5\
			)\
		) as t\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	#print(return_datas)
	ticks = time.time()
	#sql
	add_count = "INSERT INTO count_query ( count_key, count_time) VALUES ( '"+inputdata+"', '"+str(ticks)+"');"
	man_db.execute(add_count)
	return return_datas


@query.route('/wxhome',methods=['POST','GET'])
def wx_home():
    home_list = ["美妆","iphone","口红","香水","华为"]
    getkeys = random.sample(home_list, 1)[0]
    getdatas = home_query_1(getkeys)
    #print(getdatas)
    return_list = []
    for datasinfo in getdatas:
        print(datasinfo)
        print("\n\n")
        '''
        title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id
        '''
        jsondata = {
	          "goods": {
	            "imgUrl": datasinfo[0],
	            "name": datasinfo[1],
	            "price": datasinfo[3],
	            "sales": datasinfo[5],
	            "shop": datasinfo[7],
	            "pingtai": datasinfo[6],
	            "link": datasinfo[2]
	          }
          }
        return_list.append(jsondata)
        jsondata = {}
    returnjson_data = {"goodsList":return_list}
    return json.dumps(returnjson_data).encode('utf-8').decode("unicode-escape")


'''
						#类型： 接口
						#查询接口
						#使用者 ： wap
'''
@query.route('/queryData', methods=['POST','GET'])
def query_data():
    if request.method == "GET":
        keys = request.args.get('keys')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if useruuid != None:
    	getdatas = home_query_1(keys,0,useruuid)
    else:
    	getdatas = home_query_1(keys)
    #print(getdatas)
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_codlist(datasinfo))
    return render_template('querypg.html',home=1,keysinfo=keys,datalist = return_list,title = "搜索结果", cx=1)



'''
						#类型： 接口
						#查询接口
						#使用者 ： 小程序
'''
@query.route('/wxqueryData', methods=['POST','GET'])
def wx_query_data():
	pass



'''
						#类型： DB交互
						#执行查询  查询结果
'''
@ManDB
def home(man_db,pg=1):
	s_data_cout = (pg-1)*10
	end_data_cout = pg*10
	sql_cmd = "select title_img_link,cod_name,cod_link,\
				cod_price_1,cod_sales,cod_shop_location,cod_shop_name,cod_shop_home \
				from sn_pachong_data_1\
				where cod_name LIKE '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				ORDER BY cod_sales+0 DESC \
				LIMIT "+str(s_data_cout)+","+str(end_data_cout)+";"
	return_datas = man_db.execute_seles(sql_cmd)
	print(return_datas)
	return return_datas


'''
						#函数,方法
						#返回前端的数据整理
'''
def format_codlist(datasinfo):
    add_list = []
    title_img_link = datasinfo[0]
    cod_name = str(datasinfo[1])
    if len(cod_name)>20:
        cod_name = cod_name[0:20]+"..."
    cod_link = datasinfo[2]
    cod_price_1 = datasinfo[3]
    cod_price_2 = datasinfo[4]
    cod_sales = datasinfo[5]
    pingtai = datasinfo[6]
    cod_shop_name = datasinfo[7]
    cod_id = datasinfo[8]
    if len(cod_shop_name)>10:
        cod_shop_name = cod_shop_name[0:10]+"..."
    if cod_price_1 == "":
        cod_price_1 = "没有特价"
    if pingtai in ["淘宝","天猫"]:
        #print(datasinfo)
        cod_price_2 = int(cod_price_2)/100
        #print(cod_price_2)
        cod_id = "tbtm_"+str(cod_id)
    if pingtai == "京东商城":
        cod_id = "jd_"+str(cod_id)
    if pingtai == "苏宁易购":
        cod_id = "sn_"+str(cod_id)
    cod_name = cod_name.strip()
    print(cod_id)
    add_list=[title_img_link,cod_name,cod_link,
              str(cod_price_2),cod_sales,pingtai,cod_shop_name,cod_id]
    return add_list


'''
					#类型： 接口
					#搜索下拉加载商品信息
					#使用者 ： wap
'''
@query.route('/getcoddata', methods=['POST','GET'])
def getcod_pg():
    if request.method == "GET":
        keys = request.args.get('keys')
        pgnum = request.args.get('numb')
    print(keys)
    print(pgnum)
    getdatas = home_query_1(str(keys),int(pgnum))
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_codlist(datasinfo))
    resp = make_response()
    resp.status_code = 200
    #return_list=["a"]
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp


'''
						#类型： 接口
						#搜索下拉加载商品信息
						#使用者 ： 小程序
'''
@query.route('/wxgetcoddata', methods=['POST','GET'])
def wx_getcod_pg():
	pass


'''
						#类型： 接口
						# 获取大家都在买  下拉加载数据接口
						#使用者 ： wap
'''
@query.route('/getcodeveryone', methods=['POST','GET'])
def getcod_everyone():
    print("getcod_everyone  下拉请求")
    if request.method == "GET":
        pgnum = request.args.get('numb')
    print(pgnum)
    getdatas = everyone_sql(pgnum)
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_codlist(datasinfo))
    resp = make_response()
    resp.status_code = 200
    #return_list=["a"]
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp


'''
						#类型： 接口
						# 获取大家都在买  下拉加载数据接口
						#使用者 ： 小程序
'''
@query.route('/wxgetcodeveryone', methods=['POST','GET'])
def wx_getcod_everyone():
	pass


'''
						#类型： DB交互
						#获取首页数据
'''
@ManDB
def gethomedata_sql(man_db,inputdata,pgnumber=0,username = ""):
	sql="SELECT \
	title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
		(\
			SELECT title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id  \
			from sn_pachong_data_1 \
			where cod_fenlei = '"+inputdata+"'\
			AND title_img_link != 'isNull'\
			AND cod_shop_name != 'isNull'\
			AND cod_sales != 'isNull'\
			LIMIT 0,10\
		)\
		UNION\
		(\
			SELECT title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id  \
			from jd_pachong_data_1 \
			where cod_fenlei = '"+inputdata+"'\
			AND title_img_link != 'isNull'\
			AND cod_shop_name != 'isNull'\
			AND cod_sales != 'isNull'\
			LIMIT 0,10\
		)\
		UNION\
		(\
			SELECT title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id  \
			from tb_tm_pachong_data_1 \
			where cod_fenlei = '"+inputdata+"'\
			AND title_img_link != 'isNull'\
			AND cod_shop_name != 'isNull'\
			AND cod_sales != 'isNull'\
			LIMIT 0,20\
		)\
	) as t\
	"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas



'''
				#类型： 接口
				#首页商品信息下拉请求
				# home_get_fenlei  是一些默认常见分类
				#使用者 ： wap
'''
# home_get_fenlei  是一些默认常见分类
import api.home_get_fenlei as gethome_fenlei
@query.route('/getcodhome', methods=['POST','GET'])
def getcodhome_pg():
    home_list = gethome_fenlei.get_home_fenlei_data()
    getkeys = random.sample(home_list, 1)[0]
    #pgnum = random.randint(0,1)
    print(getkeys)
    #print(pgnum)
    #使用第一种
    getdatas = gethomedata_sql(getkeys)
    #使用第二种
    #getdatas = home_query_2(getkeys,pgnum)
    #print(getdatas)
    return_list = []
    for datasinfo in getdatas:    
        return_list.append(format_codlist(datasinfo))
    resp = make_response()
    resp.status_code = 200
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp


'''
#大家都在买 sql : 
0.08s
SELECT  pachong_data_id,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
from jd_pachong_data_1
where cod_sales+0 > 10000
LIMIT 0,10;
0.14s
SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
	from(
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from jd_pachong_data_1
				where cod_sales+0 > 10000
				LIMIT 0,10
			)
		UNION
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tb_tm_pachong_data_1
				where cod_sales+0 > 10000
				LIMIT 0,20
			)
		UNION
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from sn_pachong_data_1
				where cod_sales+0 > 10000
				LIMIT 0,10
			)
		) as t
'''

'''
					#类型： DB交互
					#大家都在买 sql
'''
@ManDB
def everyone_sql(man_db,pgnumber=0):
	#检查  页数是否生效
	pgnumber = int(pgnumber)
	print(type(pgnumber))
	print(pgnumber)
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1 \
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(pgnumber*5)+",10 \
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1 \
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(pgnumber*10)+",20 \
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(pgnumber*5)+",10 \
			)\
		) as t\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	return return_datas


'''
					#类型： 接口
					#大家都在买
					#使用者 ： wap
'''
@query.route('/queryeveryone', methods=['POST','GET'])
def query_everyone():
    getdatas = everyone_sql()
    #print(getdatas)
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_codlist(datasinfo))
    keys = None
    return render_template('querypg.html',home=1,keysinfo=keys,title="大家都在买",datalist = return_list,everyone = 1)



#  大家都在买 平台选择功能
# 1.1 只看淘宝天猫 - 查询
# 1.2 只看京东商城 - 查询
# 1.3 只看苏宁易购 - 查询
@ManDB
def everyone_pingtai_query_1(man_db,pingtaiType,pgnumber=0,username = ""):
	#查看是什么平台
	# tbtm =  淘宝天猫  jd = 京东  sn = 苏宁 
	print(" { everyone_pingtai_query_1 } ")
	print(pingtaiType)
	print("[pgnumber] = "+str(pgnumber))
	if pingtaiType == "tbtm":
		print("this is tb")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1 \
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "jd":
		print("this is jd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1 \
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*20)+",20 \
				"
	elif pingtaiType == "sn":
		print("this is sn")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				where cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*20)+",20 \
				"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	return return_datas


#  大家都在买 平台选择功能
@query.route('/everyonePingtai', methods=['POST','GET'])
def everyone_data_toPingtai():
    if request.method == "GET":
        pingtai = request.args.get('pingtai')
        numb = request.args.get('numb')
    
    keys = None
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if pingtai in ["tbtm","jd","sn"] and numb == None:
        if useruuid != None:
        	getdatas = everyone_pingtai_query_1(pingtai,0,useruuid)
        else:
        	getdatas = everyone_pingtai_query_1(pingtai)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        if pingtai == "tbtm":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "大家都在买",
        							everyone = 1,
        							tbtmshow=1,
        							pttype="tbtm")
        elif pingtai == "jd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "大家都在买",
        							everyone = 1,
        							jdshow=1,
        							pttype="jd")
        elif pingtai == "sn":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "大家都在买",
        							everyone = 1,
        							snshow=1,
        							pttype="sn")
    elif pingtai in ["tbtm","jd","sn"] and numb != None:
        print("[numb] = "+str(numb))
        if useruuid != None:
        	getdatas = everyone_pingtai_query_1(pingtai,numb,useruuid)
        else:
        	getdatas = everyone_pingtai_query_1(pingtai,numb)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    else:
    	return render_template('return_home.html')



'''
					#类型： 接口
					#大家都在买
					#使用者 ： 小程序
'''
@query.route('/wxqueryeveryone', methods=['POST','GET'])
def wxquery_everyone():
	pass


'''
					#类型： DB交互
					#获取jd劵
'''
@ManDB
def get_yhj_JD(man_db,pgn=0):
	sql = 'SELECT yhj_pingtai,yhj_img,yhj_guizhe,yhj_shop,yhj_link FROM yhj_jd_1 LIMIT '+str(pgn*20)+',20;'
	return_datas = man_db.execute_seles(sql)
	print(return_datas)
	return return_datas


'''
					#类型： DB交互
					#获取淘宝劵
'''
@ManDB
def get_yhj_TB(man_db,pgn=0):
	sql = 'SELECT yhj_pingtai,yhj_img,yhj_price,yhj_name,yhj_link,yhj_iniprice,yhj_sales FROM yhj_tb_1 LIMIT '+str(pgn*20)+',20;'
	return_datas = man_db.execute_seles(sql)
	print(return_datas)
	return return_datas


'''
					#类型： 接口
					#优惠劵
					#使用者 ： wap
'''
@query.route('/yhjhome',methods=['POST','GET'])
def yhj_home():
	yhj_list = []
	print("京东")
	#print(get_yhj_JD())
	jd_yhjdata = get_yhj_JD()
	print(jd_yhjdata)
	for data1 in jd_yhjdata:
		jd_data = []
		if len(data1[3]) > 11:
			jdnames = data1[3][0:11]+".."
		else:
			jdnames = data1[3]
		jd_data = [data1[0],data1[1],data1[2],jdnames,data1[4],1]
		yhj_list.append(jd_data)
	print("淘宝")
	#print(get_yhj_TB())
	tb_yhjdata = get_yhj_TB()
	print(tb_yhjdata)
	for data2 in tb_yhjdata:
		tb_data = []
		if len(data2[3]) > 11:
			tbnames = data2[3][0:11]+".."
		else:
			tbnames = data2[3]
		tb_data = [data2[0],data2[1],data2[2],tbnames,data2[4],2,data2[5],data2[6]]
		yhj_list.append(tb_data)
	print("\n\n")
	print(yhj_list)
	return render_template('YHJ_home.html',home=1,tltle = "全网找劵就上货比三家网",datalist = yhj_list)


'''
					#类型： 接口
					#优惠劵
					#使用者 ： 小程序
'''
@query.route('/wxyhjhome',methods=['POST','GET'])
def wxyhj_home():
	pass


'''	
					#类型： 接口
					#优惠劵   淘宝
					#使用者 ： wap
'''
@query.route('/yhjtb',methods=['POST','GET'])
def yhj_tb():
	yhj_list = []
	print("淘宝")
	#print(get_yhj_TB())
	tb_yhjdata = get_yhj_TB()
	print(tb_yhjdata)
	for data2 in tb_yhjdata:
		tb_data = []
		if len(data2[3]) > 11:
			tbnames = data2[3][0:11]+".."
		else:
			tbnames = data2[3]
		tb_data = [data2[0],data2[1],data2[2],tbnames,data2[4],2,data2[5],data2[6]]
		yhj_list.append(tb_data)
	print("\n\n")
	print(yhj_list)
	return render_template('YHJ_home.html',home=1,tltle = "找淘宝劵就上货比三家网",datalist = yhj_list)


'''	
					#类型： 接口
					#优惠劵   淘宝
					#使用者 ： 小程序
'''
@query.route('/wxyhjtb',methods=['POST','GET'])
def wxyhj_tb():
	pass


'''
					#类型： 接口
					#优惠劵   京东
					#使用者 ： wap
'''
@query.route('/yhjjd',methods=['POST','GET'])
def yhj_jd():
	yhj_list = []
	print("京东")
	#print(get_yhj_JD())
	jd_yhjdata = get_yhj_JD()
	print(jd_yhjdata)
	for data1 in jd_yhjdata:
		jd_data = []
		if len(data1[3]) > 11:
			jdnames = data1[3][0:11]+".."
		else:
			jdnames = data1[3]
		jd_data = [data1[0],data1[1],data1[2],jdnames,data1[4],1]
		yhj_list.append(jd_data)
	return render_template('YHJ_home.html',home=1,tltle = "找京东劵就上货比三家网",datalist = yhj_list)


'''
					#类型： 接口
					#优惠劵   京东
					#使用者 ： 小程序
'''
@query.route('/wxyhjjd',methods=['POST','GET'])
def wxyhj_jd():
	pass



'''
#  推荐您来买  推荐 功能接口 sql : 
0.118s
SELECT cod_id,ROUND(tj_fen),title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
	from(
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1
				where pingtai = '京东商城'
				LIMIT 0,10
			)
		UNION
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1
				where pingtai = '苏宁易购'
				LIMIT 0,20
			)
		) as t

'''

'''
					#类型： DB交互
					#  推荐您来买 sql
'''
@ManDB
def tjnlm_sql(man_db,pgnumber=0):
	#检查  页数是否生效
	pgnumber = int(pgnumber)
	print(type(pgnumber))
	print(pgnumber)
	sql_tjnlm ="SELECT cod_id,ROUND(tj_fen),title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
	from(\
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '京东商城' \
				LIMIT "+str(pgnumber*5)+",10 \
			)\
		UNION\
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '天猫' \
				LIMIT "+str(pgnumber*10)+",10 \
			)\
		\
		UNION\
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '淘宝' \
				LIMIT "+str(pgnumber*10)+",10 \
			)\
		\
		UNION\
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '苏宁易购' \
				LIMIT "+str(pgnumber*10)+",10 \
			)\
		\
		) as t\
	"
	print(sql_tjnlm)
	return_datas = man_db.execute_seles(sql_tjnlm)
	return return_datas


'''
					#函数,方法
					#推荐您来买  返回前端的数据整理
'''
def format_tjnlm(datasinfo):
    add_list = []
    title_img_link = datasinfo[2]
    cod_name = str(datasinfo[3])
    if len(cod_name)>20:
        cod_name = cod_name[0:20]+"..."
    cod_link = datasinfo[4]
    cod_price_1 = datasinfo[5]
    cod_price_2 = datasinfo[6]
    cod_sales = datasinfo[7]
    pingtai = datasinfo[8]
    cod_shop_name = datasinfo[9]
    cod_id = datasinfo[0]
    tj_fen = datasinfo[1]
    if len(cod_shop_name)>10:
        cod_shop_name = cod_shop_name[0:10]+"..."
    if cod_price_1 == "":
        cod_price_1 = "没有特价"
    if pingtai in ["淘宝","天猫"]:
        #print(datasinfo)
        cod_price_2 = int(cod_price_2)/100
        #print(cod_price_2)
        cod_id = "tbtm_"+str(cod_id)
    if pingtai == "京东商城":
        cod_id = "jd_"+str(cod_id)
    if pingtai == "苏宁易购":
        cod_id = "sn_"+str(cod_id)
    cod_name = cod_name.strip()
    print(cod_id)
    add_list=[title_img_link,cod_name,cod_link,
              str(cod_price_2),cod_sales,pingtai,cod_shop_name,cod_id,tj_fen]
    return add_list



'''
					#类型： 接口
					#推荐您来买   接口
					#使用者 ： wap
'''
@query.route('/tjnlm',methods=['POST','GET'])
def tjnlm_home():
    getdatas = tjnlm_sql()
    #
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_tjnlm(datasinfo))
    keys = None
    return render_template('querypg.html',home=1,keysinfo=keys,title="推荐您来买",datalist = return_list, tj = 1)
    #return str(return_list)


#  推荐您来买 平台选择功能
# 1.1 只看淘宝 - 查询
#     天猫
# 1.2 只看京东商城 - 查询
# 1.3 只看苏宁易购 - 查询
@ManDB
def tjnlm_pingtai_query_1(man_db,pingtaiType,pgnumber=0,username = ""):
	#查看是什么平台
	# tb =  淘宝  tm = 天猫  jd = 京东  sn = 苏宁  pdd = 拼多多
	print(pingtaiType)
	if pingtaiType == "tb":
		print("this is tb")
		sql = "SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '淘宝' \
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "tm":
		print("this is tm")
		sql = "SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '天猫' \
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "jd":
		print("this is jd")
		sql = "SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '京东商城' \
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "sn":
		print("this is sn")
		sql = "SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where pingtai = '苏宁易购' \
				LIMIT "+str(int(pgnumber)*20)+",20 \
				"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	return return_datas


#  推荐您来买 平台选择功能
@query.route('/tjnlmPingtai', methods=['POST','GET'])
def tjnlm_data_toPingtai():
    if request.method == "GET":
        pingtai = request.args.get('pingtai')
        numb = request.args.get('numb')
    keys = None
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if pingtai in ["tb","jd","sn","tm"] and numb == None:
        if useruuid != None:
        	getdatas = tjnlm_pingtai_query_1(pingtai,0,useruuid)
        else:
        	getdatas = tjnlm_pingtai_query_1(pingtai)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_tjnlm(datasinfo))
        if pingtai == "tb":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "推荐您来买",
        							tj = 1,
        							tbshow=1,
        							pttype="tb")
        elif pingtai == "jd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "推荐您来买",
        							tj = 1,
        							jdshow=1,
        							pttype="jd")
        elif pingtai == "sn":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "推荐您来买",
        							tj = 1,
        							snshow=1,
        							pttype="sn")
        elif pingtai == "tm":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "推荐您来买",
        							tj = 1,
        							tmshow=1,
        							pttype="tm")
    if pingtai in ["tb","jd","sn","tm"] and numb != None:
        if useruuid != None:
        	getdatas = tjnlm_pingtai_query_1(pingtai,numb,useruuid)
        else:
        	getdatas = tjnlm_pingtai_query_1(pingtai,numb)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_tjnlm(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    else:
    	return render_template('return_home.html')




'''
					#类型： 接口
					#推荐您来买   接口
					#使用者 ： 小程序
'''
@query.route('/wxtjnlm',methods=['POST','GET'])
def wxtjnlm_home():
	pass



'''
					#类型： 接口
					#下拉请求
					#使用者 ： wap
'''
@query.route('/tjnlmdata', methods=['POST','GET'])
def tjnlm_data():
    print("tjnlmdata  下拉请求")
    if request.method == "GET":
        pgnum = request.args.get('numb')
    print(pgnum)
    getdatas = tjnlm_sql(pgnum)
    return_list = []
    for datasinfo in getdatas:
        return_list.append(format_tjnlm(datasinfo))
    resp = make_response()
    resp.status_code = 200
    #return_list=["a"]
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp



'''
					#类型： 接口
					#下拉请求
					#使用者 ： 小程序
'''
@query.route('/wxtjnlmdata', methods=['POST','GET'])
def wxtjnlm_data():
    pass



'''
#商品打折   sql:
SELECT 
	cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
from(
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from sn_pachong_data_1 
			where (cod_price_2/cod_price_1) < 0.8 
			LIMIT 0,10
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from tb_tm_pachong_data_1 
			where (cod_price_1/(cod_price_2/100)) < 0.8 
			AND cod_price_1 != ""
			LIMIT 0,20
		)
) as t
'''


'''
					#类型： DB交互
					#商品打折	
'''
@ManDB
def zhekou_sql(man_db,pgnumber=0):
	print(pgnumber)
	#检查  页数是否生效
	pgnumber = int(pgnumber)
	print(type(pgnumber))
	print(pgnumber)
	sql_zhekou_tb ="\
	SELECT pachong_data_id,cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  \
				from tb_tm_pachong_data_1 \
				where cod_price_1 != ''\
				AND title_img_link != 'isNull'\
				AND (cod_price_1/(cod_price_2/100)) < 0.8\
				LIMIT "+str(pgnumber*20)+",20;\
	"
	print(sql_zhekou_tb)
	return_datas = man_db.execute_seles(sql_zhekou_tb)
	sql_zhekou_sn = "\
	SELECT pachong_data_id,cod_fenlei,title_img_link,cod_name,cod_link,cod_price_2,cod_price_1,cod_sales,pingtai,cod_shop_name  \
				from sn_pachong_data_1 \
				where (cod_price_2/cod_price_1) < 0.8 \
				AND title_img_link != 'isNull'\
				LIMIT "+str(pgnumber*10)+",10;\
	"
	return return_datas + man_db.execute_seles(sql_zhekou_sn)



'''
					#函数,方法
					#商品打折  返回前端的数据整理
'''
def format_zhekou(datasinfo):
    print(str(datasinfo))
    add_list = []
    title_img_link = datasinfo[2]
    cod_name = str(datasinfo[3])
    if len(cod_name)>20:
        cod_name = cod_name[0:20]+"..."
    cod_link = datasinfo[4]
    cod_price_1 = datasinfo[5]
    cod_price_2 = datasinfo[6]
    cod_sales = datasinfo[7]
    pingtai = datasinfo[8]
    cod_shop_name = datasinfo[9]
    cod_id = datasinfo[0]
    if len(cod_shop_name)>10:
        cod_shop_name = cod_shop_name[0:10]+"..."
    if cod_price_1 == "":
        cod_price_1 = "没有特价"
    if pingtai in ["淘宝","天猫"]:
        #print(datasinfo)
        cod_price_2 = int(cod_price_2)/100
        #print(cod_price_2)
        cod_id = "tbtm_"+str(cod_id)
    if pingtai == "京东商城":
        cod_id = "jd_"+str(cod_id)
    if pingtai == "苏宁易购":
        cod_id = "sn_"+str(cod_id)
    cod_name = cod_name.strip()
    print(cod_id)
    add_list=[title_img_link,cod_name,cod_link,str(cod_price_1),
              str(cod_price_2),cod_sales,pingtai,cod_shop_name,cod_id]
    return add_list


'''
					#类型： 接口
					#商品打折   接口
					#使用者 ： wap
'''
@query.route('/zhekou',methods=['POST','GET'])
def zhekou_home():
    datas = zhekou_sql()
    return_list = []
    for datasinfo in datas:
        return_list.append(format_zhekou(datasinfo))
    keys = None
    return render_template('youhuipg.html',home=1,keysinfo=keys,datalist = return_list)


'''
					#类型： 接口
					#商品打折   接口
					#使用者 ： 小程序
'''
@query.route('/wxzhekou',methods=['POST','GET'])
def wxzhekou_home():
	pass


'''
					#类型： 接口
					#商品打折下拉   接口
					#使用者 ： wap
'''
@query.route('/getzhekou', methods=['POST','GET'])
def get_zhekou():
    print("getzhekou  下拉请求")
    if request.method == "GET":
        pgnum = request.args.get('numb')
    print(pgnum)
    datas = zhekou_sql(pgnum)
    return_list = []
    for datasinfo in datas:
        return_list.append(format_zhekou(datasinfo))
    resp = make_response()
    resp.status_code = 200
    #return_list=["a"]
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp



'''
					#类型： 接口
					#商品打折下拉   接口
					#使用者 ： 微信
'''
@query.route('/wxgetzhekou', methods=['POST','GET'])
def wxget_zhekou():
	pass




#热搜词接口 sql
#select count_key from count_query group by count_key ORDER BY count(count_key) DESC LIMIT 6;
@ManDB
def get_rsc(man_db):
	get_rsc_sql ="select count_key from count_query group by count_key ORDER BY count(count_key) DESC LIMIT 6;"
	return_datas = man_db.execute_seles(get_rsc_sql)
	return return_datas


#分类查询接口
@query.route('/flpg', methods=['POST','GET'])
def fenlei_pg():
    return_list = get_rsc()
    getrsc_list = []
    for rsc in return_list:
    	getrsc_list.append(rsc[0])
    return render_template('fenlei.html',rsclist = getrsc_list)


#热搜词接口
@query.route('/getrsc', methods=['POST','GET'])
def getrsc():
    resp = make_response()
    resp.status_code = 200
    return_list = get_rsc()
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp



#联动查询接口
# 1. 销量优先
# 2. 价格优先
# 3. 大家都在买
# 4. 折扣/活动
# 5. 推荐您来买


#  ---   1. 销量优先 SQL  ---
@ManDB
def priority_sales_query_1(man_db,inputdata,pgnumber=0,username = ""):
	#pgnumber+=1
	print("[pgnumber] = "+str(pgnumber))
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(int(pgnumber)*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(int(pgnumber)*10)+",10\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(int(pgnumber)*5)+",5\
			)\
		) as t\
		order by cod_sales+0 DESC;\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


# 联动查询 销量优先 接口
@query.route('/prioritySales', methods=['POST','GET'])
def priority_sales():
    if request.method == "GET":
        keys = request.args.get('keys')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)

    if numb == None:
        if useruuid != None:
            getdatas = priority_sales_query_1(keys,0,useruuid)
        else:
            getdatas = priority_sales_query_1(keys)

        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return render_template('querypg.html',home=1,keysinfo=keys,datalist = return_list,title = "搜索结果", xz="销量优先", xlyx=1)
    else:
        if useruuid != None:
            getdatas = priority_sales_query_1(keys,numb,useruuid)
        else:
            getdatas = priority_sales_query_1(keys,numb)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")

    



#  销量优先 平台选择功能
# 1.1 只看淘宝天猫 - 查询
# 1.2 只看京东商城 - 查询
# 1.3 只看苏宁易购 - 查询
# 1.4 只看拼多多 - 查询
@ManDB
def prioritySales_pingtai_query_1(man_db,pingtaiType,inputdata,pgnumber=0,username = ""):
	#查看是什么平台
	# tbtm = 淘宝天猫  jd = 京东  sn = 苏宁  pdd = 拼多多
	print(pingtaiType)
	if pingtaiType == "tbtm":
		print("this is tbtm")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_sales+0 DESC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "jd":
		print("this is jd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_sales+0 DESC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "sn":
		print("this is sn")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_sales+0 DESC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "pdd":
		print("this is pdd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from pdd_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_sales+0 DESC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


#  销量优先 平台选择功能
@query.route('/prioritySalesPingtai', methods=['POST','GET'])
def prioritySales_data_toPingtai():
    if request.method == "GET":
        keys = request.args.get('keys')
        pingtai = request.args.get('pingtai')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if pingtai in ["tbtm","jd","sn","pdd"] and numb == None:
        if useruuid != None:
        	getdatas = prioritySales_pingtai_query_1(pingtai,keys,0,useruuid)
        else:
        	getdatas = prioritySales_pingtai_query_1(pingtai,keys)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        if pingtai == "tbtm":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="销量优先", 
        							xlyx=1,
        							tbtmshow=1,
        							pttype="tbtm")
        elif pingtai == "jd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="销量优先", 
        							xlyx=1,
        							jdshow=1,
        							pttype="jd")
        elif pingtai == "sn":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="销量优先", 
        							xlyx=1,
        							snshow=1,
        							pttype="sn")
        elif pingtai == "pdd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="销量优先", 
        							xlyx=1,
        							pddshow=1,
        							pttype="pdd")
    elif pingtai in ["tbtm","jd","sn","pdd"] and numb != None:
        if useruuid != None:
        	getdatas = prioritySales_pingtai_query_1(pingtai,keys,numb,useruuid)
        else:
        	getdatas = prioritySales_pingtai_query_1(pingtai,keys,numb)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    else:
    	return render_template('return_home.html')






#  ---   2. 价格优先 SQL  ---
@ManDB
def priority_price_query_1(man_db,inputdata,pgnumber=0,username = ""):
	#pgnumber+=1
	print("[pgnumber] = "+str(pgnumber))
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(int(pgnumber)*5)+",5\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				LIMIT "+str(int(pgnumber)*10)+",10\
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				AND cod_price_2 != ''\
				LIMIT "+str(int(pgnumber)*5)+",5\
			)\
		) as t\
		order by cod_price_2+0 ASC;\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


# 联动查询 价格优先 接口
@query.route('/priorityPrice', methods=['POST','GET'])
def priority_price():
    if request.method == "GET":
        keys = request.args.get('keys')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if numb == None:
        if useruuid != None:
        	getdatas = priority_price_query_1(keys,0,useruuid)
        else:
        	getdatas = priority_price_query_1(keys)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return render_template('querypg.html',home=1,keysinfo=keys,datalist = return_list,title = "搜索结果", xz="价格优先", jgyx=1)
    else:
        if useruuid != None:
        	getdatas = priority_price_query_1(keys,numb,useruuid)
        else:
        	getdatas = priority_price_query_1(keys,numb)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")



#  价格优先 平台选择功能
# 1.1 只看淘宝天猫 - 查询
# 1.2 只看京东商城 - 查询
# 1.3 只看苏宁易购 - 查询
# 1.4 只看拼多多 - 查询
@ManDB
def priorityPrice_pingtai_query_1(man_db,pingtaiType,inputdata,pgnumber=0,username = ""):
	#查看是什么平台
	# tbtm = 淘宝天猫  jd = 京东  sn = 苏宁  pdd = 拼多多
	print(pingtaiType)
	if pingtaiType == "tbtm":
		print("this is tbtm")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_price_2+0 ASC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "jd":
		print("this is jd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_price_2+0 ASC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "sn":
		print("this is sn")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_price_2+0 ASC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	elif pingtaiType == "pdd":
		print("this is pdd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from pdd_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				order by cod_price_2+0 ASC\
				LIMIT "+str(int(pgnumber)*20)+",20;\
				"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


#  价格优先 平台选择功能
@query.route('/priorityPricePingtai', methods=['POST','GET'])
def priorityPrice_data_toPingtai():
    if request.method == "GET":
        keys = request.args.get('keys')
        pingtai = request.args.get('pingtai')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if pingtai in ["tbtm","jd","sn","pdd"] and numb == None:
        if useruuid != None:
        	getdatas = priorityPrice_pingtai_query_1(pingtai,keys,0,useruuid)
        else:
        	getdatas = priorityPrice_pingtai_query_1(pingtai,keys)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        if pingtai == "tbtm":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="价格优先", 
        							jgyx=1,
        							tbtmshow=1,
        							pttype="tbtm")
        elif pingtai == "jd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="价格优先", 
        							jgyx=1,
        							jdshow=1,
        							pttype="jd")
        elif pingtai == "sn":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="价格优先", 
        							jgyx=1,
        							snshow=1,
        							pttype="sn")
        elif pingtai == "pdd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果",
        							xz="价格优先", 
        							jgyx=1,
        							pddshow=1,
        							pttype="pdd")
    elif pingtai in ["tbtm","jd","sn","pdd"] and numb != None:
        if useruuid != None:
        	getdatas = priorityPrice_pingtai_query_1(pingtai,keys,numb,useruuid)
        else:
        	getdatas = priorityPrice_pingtai_query_1(pingtai,keys,numb)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    else:
    	return render_template('return_home.html')





#  ---   3. 大家都在买 SQL  ---
@ManDB
def priority_everyone_query_1(man_db,inputdata,pgnumber=0,username = ""):
	#检查  页数是否生效
	print("[pgnumber] = "+str(pgnumber))
	sql_sqlect_all_1 ="SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
	from(\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from jd_pachong_data_1 \
				WHERE cod_name like '%"+inputdata+"%'\
				AND  cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*5)+",10 \
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from tb_tm_pachong_data_1 \
				WHERE cod_name like '%"+inputdata+"%'\
				AND  cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*10)+",20 \
			)\
		UNION\
			(SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id\
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				AND  cod_sales+0 > 10000 \
				AND title_img_link != 'isNull' \
				AND cod_shop_name != 'isNull' \
				LIMIT "+str(int(pgnumber)*5)+",10 \
			)\
		) as t\
	"
	print(sql_sqlect_all_1)
	return_datas = man_db.execute_seles(sql_sqlect_all_1)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas


# 联动查询 大家都在买 接口
@query.route('/priorityEveryone', methods=['POST','GET'])
def priority_everyone():
    if request.method == "GET":
        keys = request.args.get('keys')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if numb == None:
        if useruuid != None:
            getdatas = priority_everyone_query_1(keys,0,useruuid)
        else:
            getdatas = priority_everyone_query_1(keys)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return render_template('querypg.html',home=1,keysinfo=keys,datalist = return_list,title = "搜索结果", xz="大家都在买")
    else:
        if useruuid != None:
            getdatas = priority_everyone_query_1(keys,numb,useruuid)
        else:
            getdatas = priority_everyone_query_1(keys,numb)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")



#  ---   4. 折扣/活动 SQL  ---
@ManDB
def priority_zhekou_query_1(man_db,inputdata,pgnumber=0,username = ""):
	print("[pgnumber] = "+str(pgnumber))
	sql_zhekou_tb ="\
	SELECT pachong_data_id,cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  \
				from tb_tm_pachong_data_1 \
				where cod_name like '%"+inputdata+"%'\
				AND cod_price_1 != ''\
				AND title_img_link != 'isNull'\
				AND (cod_price_1/(cod_price_2/100)) < 0.8\
				LIMIT "+str(int(pgnumber)*20)+",20;\
	"
	print(sql_zhekou_tb)
	return_datas = man_db.execute_seles(sql_zhekou_tb)
	sql_zhekou_sn = "\
	SELECT pachong_data_id,cod_fenlei,title_img_link,cod_name,cod_link,cod_price_2,cod_price_1,cod_sales,pingtai,cod_shop_name  \
				from sn_pachong_data_1 \
				where cod_name like '%"+inputdata+"%'\
				AND (cod_price_2/cod_price_1) < 0.8 \
				AND title_img_link != 'isNull'\
				LIMIT "+str(int(pgnumber)*10)+",10;\
	"
	return return_datas + man_db.execute_seles(sql_zhekou_sn)


# 联动查询 折扣/活动 接口
@query.route('/priorityZhekou', methods=['POST','GET'])
def priority_zhekou():
    if request.method == "GET":
        keys = request.args.get('keys')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if numb == None:
        if useruuid != None:
            getdatas = priority_zhekou_query_1(keys,0,useruuid)
        else:
            getdatas = priority_zhekou_query_1(keys)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_zhekou(datasinfo))
        return render_template('querypg.html',
    						    home=1,
    						    keysinfo=keys,
    						    datalist = return_list,
    						    title = "搜索结果", 
    						    xz="折扣/活动",
    						    zhekoushow = 1)
    else:
        if useruuid != None:
            getdatas = priority_zhekou_query_1(keys,numb,useruuid)
        else:
            getdatas = priority_zhekou_query_1(keys,numb)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_zhekou(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")



#  ---   5. 推荐您来买 SQL  ---
@ManDB
def priority_tjnlm_query_1(man_db,inputdata,pgnumber=0,username = ""):
	print("[pgnumber] = "+str(pgnumber))
	sql_tjnlm ="SELECT cod_id,ROUND(tj_fen),title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name\
				from tj_info_1 \
				where cod_name like '%"+inputdata+"%'\
				AND pingtai in ('天猫','京东商城','淘宝','苏宁易购')\
				LIMIT "+str(int(pgnumber)*40)+",40\
	"
	print(sql_tjnlm)
	return_datas = man_db.execute_seles(sql_tjnlm)
	return return_datas


# 联动查询 推荐您来买 接口
@query.route('/priorityTjnlm', methods=['POST','GET'])
def priority_tjnlm():
    if request.method == "GET":
        keys = request.args.get('keys')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid)
    if numb == None:
        if useruuid != None:
            getdatas = priority_tjnlm_query_1(keys,0,useruuid)
        else:
            getdatas = priority_tjnlm_query_1(keys)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_tjnlm(datasinfo))
        return render_template('querypg.html',home=1,keysinfo=keys,datalist = return_list,title = "搜索结果", xz="推荐您来买")
    else:
        if useruuid != None:
            getdatas = priority_tjnlm_query_1(keys,numb,useruuid)
        else:
            getdatas = priority_tjnlm_query_1(keys,numb)
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_tjnlm(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")





#  普通查询后 平台选择功能
# 1.1 只看淘宝天猫 - 查询
# 1.2 只看京东商城 - 查询
# 1.3 只看苏宁易购 - 查询
# 1.4 只看拼多多 - 查询
@ManDB
def only_pingtai_query_1(man_db,pingtaiType,inputdata,pgnumber=0,username = ""):
	#查看是什么平台
	# tbtm = 淘宝天猫  jd = 京东  sn = 苏宁  pdd = 拼多多
	print(pingtaiType)
	if pingtaiType == "tbtm":
		print("this is tbtm")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from tb_tm_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				\
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "jd":
		print("this is jd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from jd_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				\
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "sn":
		print("this is sn")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from sn_pachong_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				\
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	elif pingtaiType == "pdd":
		print("this is pdd")
		sql = "SELECT title_img_link,cod_name,cod_link,\
				cod_price_1,cod_sales,pingtai,cod_shop_name,pachong_data_id \
				from pdd_data_1\
				WHERE cod_name like '%"+inputdata+"%'\
				\
				AND title_img_link != 'isNull'\
				AND cod_shop_name != 'isNull'\
				\
				LIMIT "+str(int(pgnumber)*20)+",20\
				"
	print(sql)
	return_datas = man_db.execute_seles(sql)
	#print(return_datas)
	ticks = time.time()
	add_count = "INSERT INTO count_query ( count_key, count_time, user_uuid) VALUES ( '"+inputdata+"', '"+str(ticks)+"','"+username+"');"
	man_db.execute(add_count)
	return return_datas



# 平台选择功能 测试 接口
@query.route('/pingtaitest', methods=['POST','GET'])
def pingtaitest():
    resp = make_response()
    resp.status_code = 200
    return_list = only_pingtai_query_1("pdd","手机")
    print(return_list)
    resp.response = json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    return resp


#  普通查询后 平台选择功能
# 1.1 只看淘宝天猫 - 查询
@query.route('/queryDataPingtai', methods=['POST','GET'])
def query_data_toPingtai():
    if request.method == "GET":
        keys = request.args.get('keys')
        pingtai = request.args.get('pingtai')
        numb = request.args.get('numb')
    useruuid=request.cookies.get('user_uuid')
    print(useruuid) 
    if pingtai in ["tbtm","jd","sn","pdd"] and numb == None:
        if useruuid != None:
        	getdatas = only_pingtai_query_1(pingtai,keys,0,useruuid)
        else:
        	getdatas = only_pingtai_query_1(pingtai,keys)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        if pingtai == "tbtm":
        	# @pttype 下拉带的参数   @tbtmshow 用于前端按钮显示  @cx  表示在查询
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果", 
        							cx=1,
        							tbtmshow=1,
        							pttype="tbtm")
        elif pingtai == "jd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果", 
        							cx=1,
        							jdshow=1,
        							pttype="jd")
        elif pingtai == "sn":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果", 
        							cx=1,
        							snshow=1,
        							pttype="sn")
        elif pingtai == "pdd":
        	return render_template('querypg.html',
        							home=1,
        							keysinfo=keys,
        							datalist = return_list,
        							title = "搜索结果", 
        							cx=1,
        							pddshow=1,
        							pttype="pdd")
    elif pingtai in ["tbtm","jd","sn","pdd"] and numb != None:
        if useruuid != None:
        	getdatas = only_pingtai_query_1(pingtai,keys,numb,useruuid)
        else:
        	getdatas = only_pingtai_query_1(pingtai,keys,numb)
        #print(getdatas)    
        return_list = []
        for datasinfo in getdatas:
            return_list.append(format_codlist(datasinfo))
        return json.dumps(return_list).encode('utf-8').decode("unicode-escape")
    else:
    	return render_template('return_home.html')






"""
								[ sql ]

首页和查询
SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
	from(
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from jd_pachong_data_1
				WHERE cod_fenlei = '手机'
				AND title_img_link != 'isNull'
				AND cod_shop_name != 'isNull'
				LIMIT 0,5
			)
		UNION
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tb_tm_pachong_data_1
				WHERE cod_fenlei = '手机'
				AND title_img_link != 'isNull'
				AND cod_shop_name != 'isNull'
				LIMIT 0,10
			)
		UNION
			(SELECT title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from sn_pachong_data_1
				WHERE cod_fenlei = '手机'
				AND title_img_link != 'isNull'
				AND cod_shop_name != 'isNull'
				LIMIT 0,5
			)
		) as t



商品打折
SELECT * from sn_pachong_data_1 where (cod_price_2/cod_price_1) < 0.8 LIMIT 10;

SELECT * from tb_tm_pachong_data_1 
where 
(cod_price_1/(cod_price_2/100)) < 0.8 
AND
cod_price_1 != ""
LIMIT 10;

SELECT 
	cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
from(
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from sn_pachong_data_1 
			where (cod_price_2/cod_price_1) < 0.8 
			LIMIT 0,10
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from tb_tm_pachong_data_1 
			where (cod_price_1/(cod_price_2/100)) < 0.8 
			AND cod_price_1 != ""
			LIMIT 0,20
		)
) as t


#大家都在买

1s

SELECT 
	cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
from jd_pachong_data_1
WHERE title_img_link != 'isNull'
AND cod_shop_name != 'isNull'
AND cod_sales != 'isNull'
ORDER BY cod_sales+0 DESC
LIMIT 0,10;

9s

SELECT 
	cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
from(
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from jd_pachong_data_1
			WHERE title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			ORDER BY cod_sales+0 DESC
			LIMIT 0,10
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from tb_tm_pachong_data_1 
			WHERE title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			ORDER BY cod_sales+0 DESC
			LIMIT 0,20
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from sn_pachong_data_1 
			WHERE title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			ORDER BY cod_sales+0 DESC
			LIMIT 0,10
		)
) as t

6s

SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from tb_tm_pachong_data_1 
			WHERE title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			AND cod_sales != 'isNull'
			ORDER BY cod_sales+0 DESC
			LIMIT 0,10;

14S

SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from JD_pachong_data_1 
			WHERE title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			AND cod_sales != 'isNull'
			ORDER BY cod_sales+0 DESC
			LIMIT 0,10;



#分类查询 

SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from sn_pachong_data_1 
			where cod_fenlei = "T恤"
			LIMIT 0,10;

0.2

SELECT 
	cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name 
from(
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from sn_pachong_data_1 
			where cod_fenlei = "T恤"
			AND title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			AND cod_sales != 'isNull'
			LIMIT 0,10
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from jd_pachong_data_1 
			where cod_fenlei = "T恤"
			AND title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			AND cod_sales != 'isNull'
			LIMIT 0,10
		)
		UNION
		(
			SELECT cod_fenlei,title_img_link,cod_name,cod_link,cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name  
			from tb_tm_pachong_data_1 
			where cod_fenlei = "T恤"
			AND title_img_link != 'isNull'
			AND cod_shop_name != 'isNull'
			AND cod_sales != 'isNull'
			LIMIT 0,20
		)
) as t
;


#推荐您来买
SELECT cod_id,ROUND(tj_fen),title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
	from(
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1 
				where pingtai = '京东商城' 
				LIMIT 0,10 
			)
		UNION
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1 
				where pingtai = '天猫' 
				LIMIT 0,10 
			)
		UNION
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1 
				where pingtai = '淘宝' 
				LIMIT 0,10 
			)
		UNION
			(SELECT cod_id,tj_fen,title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1 
				where pingtai = '苏宁易购' 
				LIMIT 0,10
			)
		) as t;


SELECT cod_id,ROUND(tj_fen),title_img_link,cod_name,cod_link,
				cod_price_1,cod_price_2,cod_sales,pingtai,cod_shop_name
				from tj_info_1 
				where cod_name like '%手机%'
				AND pingtai in ('天猫','京东商城','淘宝','苏宁易购')
				LIMIT 0,40


"""

